package net.techwatch.gwt.mvp.server;

import net.techwatch.gwt.mvp.client.service.Action;
import net.techwatch.gwt.mvp.client.service.GetName;
import net.techwatch.gwt.mvp.client.service.GetNameResponse;
import net.techwatch.gwt.mvp.client.service.GreetingService;
import net.techwatch.gwt.mvp.client.service.Response;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**
 * The server side implementation of the RPC service.
 */
@SuppressWarnings("serial")
public class GreetingServiceImpl extends RemoteServiceServlet implements
		GreetingService {

	@Override
	public <T extends Response> T execute(Action<T> action) {
		String serverInfo = getServletContext().getServerInfo();
		String userAgent = getThreadLocalRequest().getHeader("User-Agent");
		return (T) new GetNameResponse("Hello, " + ((GetName) action).getName() + "!<br><br>I am running " + serverInfo
				+ ".<br><br>It looks like you are using:<br>" + userAgent);
	}
}
